// extract modules
var http = require('http');
var fs = require('fs');
var socketio = require('socket.io');

var server = http.createServer(function(request, response) {
	// read html page
	fs.readFile('resources/basic.html', function(error, data) {
		response.writeHead(200, {'Content-Type': 'text/html'});
		response.end(data);
	});
}).listen(52273, function() {
	console.log('Server running at 127.0.0.1');
});

// create and run socket server
var io = socketio.listen(server);
io.sockets.on('connection', function(socket) {
	// send event handler
	socket.on('send', function(data) {
		// broadcast type
		socket.broadcast.emit('response', data);
	});
});